home *** CD-ROM | disk | FTP | other *** search
- Use the following declaration:
-
- class Frob {
- public:
- Rettype f(T1 x, T2 y);
- Rettype g(T1 x, T2 y);
- Rettype h(T1 x, T2 y);
- Rettype i(T1 x, T2 y);
- //...
- };
-
- Rettype (Frob::*fn_ptr[3])(T1,T2) = { &Frob::f, &Frob::g, &Frob::h };
-
- You can make the array declaration somewhat clearer with a typedef:
- typedef Rettype (Frob::*Frob_member_ptr)(T1,T2);
- //...
- Frob_member_ptr fn_ptr[3] = { &Frob::f, &Frob::g, &Frob::h };
-
- To call one of the functions on an object 'frob', use:
- Frob frob;
- //...
- (frob.*fn_ptr[i])(x, y);
-
- You can make the call somewhat clearer using a #define:
- #define apply_member_fn(object,fn) ((object).*(fn))
- //...
- apply_member_fn(frob,fn_ptr[i])(x, y)